package kltn.business;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class MyAsyntask extends AsyncTask<String, String, String>{
	 Activity contextCha;
	 String version;
	 public MyAsyntask(Activity ctx,String ver)
	 {
		 contextCha=ctx;
		 version=ver;
	 }
	 @Override
	 protected void onPreExecute() {
		 super.onPreExecute();
//		 Toast.makeText(contextCha, "onPreExecute!",Toast.LENGTH_LONG).show();
	 }
	@Override
	protected String doInBackground(String... params) {
		String line = null;
		StringBuffer value = new StringBuffer();
		String path = "https://dl.dropboxusercontent.com/s/qq4dnyl1g5gwy50/Data.txt?dl=1&token_hash=AAHbhFN9P8L5bHXkklaBiCSEcLeh7eYhsRvlX0DnMBGk1w";
		try {
			HttpURLConnection connection=((HttpURLConnection)(new URL(path)).openConnection());
			int fileLength = connection.getContentLength();
			InputStream is = connection.getInputStream();
			BufferedReader bufferedReader = new BufferedReader(
					new InputStreamReader(is));
			Log.d("test",fileLength+"byte");
			while ((line = bufferedReader.readLine()) != null) {
				value.append(line + "\n");
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return line;
	}
	@Override
	protected void onProgressUpdate(String... values) {
		super.onProgressUpdate(values);
	}

	@SuppressLint("NewApi")
	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		//
//		if (!result.isEmpty()){
//		}
//		else
//			Toast.makeText(contextCha, "Value is null",
//					Toast.LENGTH_LONG).show();
	}

}
